from flask_restful import Api

import importlib


from controller.sysinfo.UserController import *
from controller.project.MachineController import *

app_module = importlib.import_module('controller.work.AppController')
class_app = getattr(app_module, 'AppController')
revalid_app = getattr(app_module, 'AppRevalidGenMarkdownController')

sysinfo_user = '/sysinfo/user'
project_machine = '/project/machine'

PAGINATION = '/pagination'
ITEM_ID = '/<item_id>'

urls = [
    # sysinfo_user
    (UserController, sysinfo_user, ''),
    (UserPaginationController, sysinfo_user, PAGINATION),
    (UserDeleteByIdController, sysinfo_user, ITEM_ID),
    (UserGetByIdController, sysinfo_user, ITEM_ID),
    # project_machine
    (MachineController, project_machine, ''),
    (MachineGetByIdController, project_machine, ITEM_ID),
    (MachineUploadPictureController, project_machine, '/upload_picture'),
    (MachineDownloadPictureController, project_machine, '/download_picture'),
    # work_app
    (class_app, '/work/app', ''),
    (revalid_app, '/work/app', '/revalid_gen_markdown')

]


def create_routes(app):
    api = Api(app)
    # 遍历添加路由
    for url in urls:
        api.add_resource(url[0], url[1] + url[2])
